# example6_23_contourf_contour.py
# coding=utf-8
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm

n = 512
x = np.linspace(-2.5, 2.5, n)
y = np.linspace(-2.5, 2.5, n)
# 将x、y变成网格数据
X, Y = np.meshgrid(x, y)
# 根据X、Y的值计算高度Z
Z = (X**3 + Y) * np.exp(-(X**2) - Y**2)
# 添加等高线
C = plt.contour(X, Y, Z, 8, colors="black", linewidths=0.8, linestyles="dashed")
# 显示各条等高线的数据标签
plt.clabel(C, inline=True, fontsize=12)
# 为等高线之间填充颜色
plt.contourf(X, Y, Z, 8, alpha=0.75, cmap=cm.inferno)

plt.show()
